package com.cluster.platform.controller;

import com.cluster.platform.common.api.CommonResult;
import com.cluster.platform.model.CmsCommentsInfo;
import com.cluster.platform.service.CmsCommentsInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 评论功能接口
 *
 * @ClassName: CmsCommentsInfoController
 */
@Controller
@Api(tags = "CmsCommentsInfoController", value = "评论功能接口")
@RequestMapping("/commentsInfo")
public class CmsCommentsInfoController {

    @Autowired
    private CmsCommentsInfoService cmsCommentsInfoService;

    /**
     * 新增评论
     */
    @ApiOperation("新增评论")
    @RequestMapping(value = "/addComments", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CmsCommentsInfo> addComments(@RequestBody CmsCommentsInfo cmsCommentsInfo) {
        return cmsCommentsInfoService.addComments(cmsCommentsInfo);
    }

    /**
     * 删除评论
     */
    @ApiOperation("删除评论")
    @RequestMapping(value = "/delComments", method = RequestMethod.DELETE)
    @ResponseBody
    public CommonResult<Object> delComments(@RequestParam("id") String id) {
        return cmsCommentsInfoService.deleteComments(id);
    }

    /**
     * 批量删除评论
     */
    @ApiOperation("批量删除评论")
    @RequestMapping(value = "/batchDelComments", method = RequestMethod.DELETE)
    @ResponseBody
    public CommonResult<Object> batchDelComments(List<CmsCommentsInfo> cmsCommentsInfos) {
        return cmsCommentsInfoService.batchDeleteComments(cmsCommentsInfos);
    }

    /**
     * 查询评论数据
     */
    @ApiOperation("查询评论")
    @RequestMapping(value = "/searchComments", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<Object> searchComments(@RequestBody CmsCommentsInfo cmsCommentsInfo) {
        return cmsCommentsInfoService.searchComments(cmsCommentsInfo);
    }

    /**
     * 分页查询评论
     */
    @ApiOperation("分页查询评论")
    @RequestMapping(value = "/searchCommentsPage", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<Object> searchCommentsPage(CmsCommentsInfo cmsCommentsInfo, Integer pageNum, Integer pageSize) {
        return cmsCommentsInfoService.searchCommentsPage(cmsCommentsInfo, pageNum, pageSize);
    }

    // 根据文章ID查询评论信息
    @ApiOperation("根据文章ID查询评论信息")
    @RequestMapping(value = "/searchCommentsByTopicId", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<Object> searchCommentsByTopicId(@RequestParam("topicId") String topicId) {
        return cmsCommentsInfoService.searchCommentsByTopicId(topicId);
    }
}
